package test46;


/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-05-18
 * Time: 16:05
 */
public class Main {
}

class Solution {
    public int MoreThanHalfNum_Solution(int [] array) {
        int n = array.length;
        int cond = -1;
        int cnt = 0;
        for (int j : array) {
            if (cnt == 0) {
                cond = j;
                cnt++;
            } else {
                if (cond == j) {
                    cnt++;
                } else {
                    cnt--;
                }
            }
        }
        cnt = 0;
        for (int ele : array) {
            if (ele == cond) {
                cnt++;
            }
        }
        if (cnt > n / 2) {
            return cond;
        }
        return 0;
    }
}
